package smedi.ismedi.web.bff.controller.quality;

import com.smedi.ismedi.authority.starter.common.ResponseData;
import com.smedi.ismedi.file.dto.response.FileInfoResponse;
import com.smedi.ismedi.file.feign.RemoteFileFeignApi;
import com.smedi.ismedi.instrument.api.dto.request.overview.*;
import com.smedi.ismedi.instrument.api.dto.response.overview.*;
import com.smedi.ismedi.instrument.api.feign.RemoteQualityOverViewFeignApi;
import com.smedi.ismedi.web.starter.common.PaginationData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import smedi.ismedi.web.bff.infrastructure.util.FileHelper;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @className: QualityOverViewController
 * @Description: 质量看板
 * @version: v1.0.0
 * @author: wzx
 * @date: 2022/10/27 15:56
 */

@Slf4j
@RestController
@Api(tags = {"质量看板接口"} ,value = "质量看板接口")
@RequestMapping("/webbff/v1/overview")
@RequiredArgsConstructor
public class QualityOverViewController {

    private final RemoteQualityOverViewFeignApi overViewFeignApi;

    private final RemoteFileFeignApi fileFeignApi;

    @Value("${fdfs.service.address.in}")
    private String FDFS_SERVICE_ADDRESS_IN;

    /**
     * 质量检查总数总院
     */
    @ApiOperation(value = "质量检查总数总院", httpMethod = "GET")
    @GetMapping("/qualityCheck/summary")
    ResponseData<QualityCheckSummaryResponse> qualityCheckSummary(){
        return overViewFeignApi.qualityCheckSummary();
    }

    /**
     * 质量检查总数主体院
     */
    @ApiOperation(value = "质量检查总数主体院", httpMethod = "GET")
    @GetMapping("/qualityCheck/summary/org")
    ResponseData<QualityCheckSummaryResponse> qualityCheckSummaryOrg(){
        return overViewFeignApi.qualityCheckSummaryOrg();
    }

    /**
     * 质量检查总数项目
     */
    @ApiOperation(value = "质量检查总数项目", httpMethod = "GET")
    @GetMapping("/qualityCheck/summary/project")
    ResponseData<QualityCheckSummaryResponse> qualityCheckSummaryProject(){
        return overViewFeignApi.qualityCheckSummaryProject();
    }

    /**
     * 验收总结
     */
    @ApiOperation(value = "竣工验收项目总数", httpMethod = "GET")
    @GetMapping("/reportAccept/summary")
    ResponseData<ReportAcceptSummaryResponse> getReportAcceptSummary(){
        return overViewFeignApi.getReportAcceptSummary();
    }

    /**
     * 年度获奖工程总数
     */
    @ApiOperation(value = "年度获奖工程总数", httpMethod = "GET")
    @GetMapping("/reportTrack/summary")
    ResponseData<Integer> getReportTrackSummary(){
        return overViewFeignApi.getReportTrackSummary();
    }

    /**
     * 计量器具检测统计
     */
    @ApiOperation(value = "计量器具统计", httpMethod = "GET")
    @GetMapping("/instrument/summary")
    ResponseData<InstrumentSummaryResponse> instrumentSummary(){
        return overViewFeignApi.instrumentSummary();
    }

    /**
     * QC活动小组 总院
     * */
    @ApiOperation(value = "QC活动小组数量 总院", httpMethod = "GET")
    @GetMapping("/team/summary")
    ResponseData<QCTeamSummaryResponse> teamSummary(){
        return overViewFeignApi.teamSummary();
    }

    /**
     * QC活动小组 主体院
     */
    @ApiOperation(value = "QC活动小组数量 主体院", httpMethod = "GET")
    @GetMapping("/team/summary/{orgId}")
    ResponseData<QCTeamSummaryResponse> teamSummary(@PathVariable Long orgId){
        return overViewFeignApi.teamSummary(orgId);
    }

    /**
     * QC课题总数 看板统计 总院
     */
    @ApiOperation(httpMethod = "GET", value = "QC课题数量")
    @GetMapping("/subject/summary")
    ResponseData<SubjectSummaryResponse> subjectSummary(){
        return overViewFeignApi.subjectSummary();
    }

    /**
     * QC课题总数 看板统计 主体院
     */
    @ApiOperation(httpMethod = "GET", value = "QC课题数量 主体院")
    @GetMapping("/subject/summary/{orgId}")
    ResponseData<SubjectSummaryResponse> subjectSummary(@PathVariable Long orgId){
        return overViewFeignApi.subjectSummary(orgId);
    }

    /**
     * 本年竣工验收项目
     *
     * @param request 竣工验收项目 分页请求
     */
    @ApiOperation(value = "本年竣工验收项目", httpMethod = "POST")
    @PostMapping("/reportAccept")
    ResponseData<PaginationData<ReportAcceptOverViewResponse>> reportAccept(@Validated @RequestBody ReportAcceptOverViewRequest request){
        return overViewFeignApi.reportAccept(request);
    }


    /**
     * QC活动情况统计 小组分布统计 总院
     * */
    @ApiOperation(httpMethod = "POST", value = "QC情况统计 小组分布统计")
    @PostMapping("/team/distribute")
    ResponseData<PaginationData<TeamDistributeOverViewResponse>> teamDistribute(@Validated @RequestBody TeamDistributeOverViewRequest request){
        return overViewFeignApi.teamDistribute(request);
    }

    /**
     * QC活动情况统计 QC课题情况统计 按类型统计
     * */
    @ApiOperation(httpMethod = "GET", value = "QC活动情况统计 QC课题情况统计 按类型统计 总院")
    @GetMapping("/subject/distribute/type")
    ResponseData<List<SubjectDistributeTypeOverViewResponse>> subjectDistributeByType(){
        return overViewFeignApi.subjectDistributeByType();
    }

    /**
     * QC活动情况统计 QC课题情况统计 按状态统计
     * */
    @ApiOperation(httpMethod = "GET", value = "QC活动情况统计 QC课题情况统计 按状态统计 总院")
    @GetMapping("/subject/distribute/status")
    ResponseData<List<SubjectDistributeStatusOverViewResponse>> subjectDistributeByStatus(){
        return overViewFeignApi.subjectDistributeByStatus();
    }

    /**
     * QC活动情况统计 QC课题情况统计 按类型统计
     * */
    @ApiOperation(httpMethod = "GET", value = "QC活动情况统计 QC课题情况统计 按类型统计 主体院")
    @GetMapping("/subject/distribute/type/{orgId}")
    ResponseData<List<SubjectDistributeTypeOverViewResponse>> subjectDistributeByType(@PathVariable Long orgId){
        return overViewFeignApi.subjectDistributeByType(orgId);
    }

    /**
     * QC活动情况统计 QC课题情况统计 按状态统计
     * */
    @ApiOperation(httpMethod = "GET", value = "QC活动情况统计 QC课题情况统计 按状态统计 主体院")
    @GetMapping("/subject/distribute/status/{orgId}")
    ResponseData<List<SubjectDistributeStatusOverViewResponse>> subjectDistributeByStatus(@PathVariable Long orgId){
        return overViewFeignApi.subjectDistributeByStatus(orgId);
    }

    /**
     * QC小组一览 主体院
     * */
    @ApiOperation(httpMethod = "POST", value = "QC小组一览 主体院")
    @PostMapping("/team/list")
    ResponseData<PaginationData<TeamListOverViewResponse>> teamListPage(@Validated @RequestBody TeamListOverViewRequest request){
        return overViewFeignApi.teamListPage(request);
    }

    /**
     * 质量隐患看板统计
     *
     * @param hiddenDangerOverViewRequest 分页请求
     */
    @ApiOperation(value = "质量隐患统计", httpMethod = "POST")
    @PostMapping("/hiddenDanger")
    ResponseData<PaginationData<HiddenDangerOverViewResponse>> hiddenDangerOverView(@Validated @RequestBody HiddenDangerOverViewRequest hiddenDangerOverViewRequest){
        return overViewFeignApi.hiddenDangerOverView(hiddenDangerOverViewRequest);
    }

    /**
     * 质量检查(隐患)看板统计 柱状图
     *
     * @param request 质量检查(隐患)请求
     */
    @ApiOperation(value = "质量检查(隐患 主体院、总院级别)统计 柱状图", httpMethod = "POST")
    @PostMapping("/qualityCheckHiddenDanger")
    ResponseData<List<QualityCheckOverViewResponse>> qualityCheckHiddenDangerOverView(@Validated @RequestBody QualityCheckOverViewRequest request){
        return overViewFeignApi.qualityCheckHiddenDangerOverView(request);
    }


    /**
     * 质量检查(隐患)看板统计 折线图
     *
     * @param request 质量检查(隐患)请求
     */
    @ApiOperation(value = "质量检查(隐患)统计 折线图", httpMethod = "POST")
    @PostMapping("/qualityCheckHiddenDanger/line")
    ResponseData<List<QualityCheckHiddenDangerLineResponse>> qualityCheckHiddenDangerLine(@Validated @RequestBody HiddenDangerLineOverViewRequest request){
        return overViewFeignApi.qualityCheckHiddenDangerLine(request);
    }


    /**
     * 质量检查(检查)看板统计 柱状图
     *
     * @param request 质量检查(检查)请求
     */
    @ApiOperation(value = "质量检查(检查 主体院、总院级别)统计 柱状图", httpMethod = "POST")
    @PostMapping("/qualityCheck")
    ResponseData<List<QualityCheckOverViewResponse>> qualityCheckOverView(@Validated @RequestBody QualityCheckOverViewRequest request){
        return overViewFeignApi.qualityCheckOverView(request);
    }

    /**
     * 质量检查(检查)看板统计 折线图
     *
     * @param request 质量检查(检查)请求
     */
    @ApiOperation(value = "质量检查(检查)统计 折线图", httpMethod = "POST")
    @PostMapping("/qualityCheck/line")
    ResponseData<List<QualityCheckLineResponse>> qualityCheckLine(@Validated @RequestBody QualityCheckLineOverViewRequest request){
        return overViewFeignApi.qualityCheckLine(request);
    }

    /**
     * 质量隐患总数 项目级别 总结
     */
    @ApiOperation(value = "质量隐患总数 项目级别 总结", httpMethod = "GET")
    @GetMapping("/hiddenDanger/summary")
    ResponseData<HiddenDangerSummaryResponse> hiddenDangerSummary(){
        return overViewFeignApi.hiddenDangerSummary();
    }

    /**
     * 计量器具总数 项目级别
     */
    @ApiOperation(value = "计量器具总数 项目级别", httpMethod = "GET")
    @GetMapping("/instrument/project/summary")
    ResponseData<InstrumentProjectSummaryResponse> instrumentProjectSummary(){
        return overViewFeignApi.instrumentProjectSummary();
    }

    /**
     * 每月隐患数量
     */
    @ApiOperation(value = "每月隐患数量", httpMethod = "GET")
    @GetMapping("/hiddenDanger/project/{year}")
    ResponseData<List<HiddenDangerProjectMonthOverViewResponse>> hiddenDangerMonth(@PathVariable Integer year){
        return overViewFeignApi.hiddenDangerMonth(year);
    }


    /**
     * 质量隐患 项目级别 隐患排行
     *
     * @param hiddenDangerOverViewRequest 分页请求
     */
    @ApiOperation(value = "隐患排行 项目级别", httpMethod = "POST")
    @PostMapping("/hiddenDanger/sort")
    ResponseData<PaginationData<HiddenDangerSortResponse>> hiddenDangerSort(@Validated @RequestBody HiddenDangerOverViewRequest hiddenDangerOverViewRequest){
        return overViewFeignApi.hiddenDangerSort(hiddenDangerOverViewRequest);
    }

    /**
     * 质量检查(检查 项目级别)看板统计
     *
     * @param request 请求维度
     */
    @ApiOperation(value = "质量检查(检查 项目级别)", httpMethod = "POST")
    @PostMapping("/qualityCheck/project")
    ResponseData<List<QualityCheckProjectOverViewResponse>> qualityCheckProject(@Validated @RequestBody QualityCheckProjectOverViewRequest request){
        return overViewFeignApi.qualityCheckProject(request);
    }

    /**
     * 计量器具列表 项目级别
     * */
    @ApiOperation(httpMethod = "POST", value = "计量器具列表 项目")
    @PostMapping("/instrument/project/list")
    ResponseData<PaginationData<InstrumentPageOverViewResponse>> instrumentProjectPage(@Validated @RequestBody InstrumentProjectOverViewRequest request){
        return overViewFeignApi.instrumentProjectPage(request);
    }

    /**
     * 质量看板 总结 总院
     */
    @ApiOperation(httpMethod = "GET", value = "质量看板 总结 总院")
    @GetMapping("/summary")
    ResponseData<QualityOverViewSummaryResponse> summary(){
        return overViewFeignApi.summary();
    }

    /**
     * 质量看板 总结 主体院
     */
    @ApiOperation(httpMethod = "GET", value = "质量看板 总结 主体院")
    @GetMapping("/summary/org/{orgId}")
    ResponseData<QualityOverViewSummaryResponse> summaryOrg(@PathVariable Long orgId){
        return overViewFeignApi.summaryOrg(orgId);
    }

    /**
     * 质量看板 总结 项目
     */
    @ApiOperation(httpMethod = "GET", value = "质量看板 总结 项目")
    @GetMapping("/summary/project")
    ResponseData<QualityOverViewSummaryProjectResponse> summaryProject(){
        return overViewFeignApi.summaryProject();
    }

    @ApiOperation(httpMethod = "POST",value = "质量检查统计 主体院")
    @PostMapping(value = "/qualityCheck/statistics")
    ResponseData<QualityCheckStatisticsOverViewResponse> qualityCheckStatistics(@Validated @RequestBody QualityCheckStatisticRequest qualityCheckStatisticRequest){
        return overViewFeignApi.qualityCheckStatistics(qualityCheckStatisticRequest);
    }

    @ApiOperation(httpMethod = "POST",value = "质量检查统计 项目")
    @PostMapping(value = "/qualityCheck/statistics/project")
    ResponseData<QualityCheckStatisticsOverViewResponse> qualityCheckStatisticsProject(@Validated @RequestBody QualityCheckStatisticRequest qualityCheckStatisticRequest){
        return overViewFeignApi.qualityCheckStatisticsProject(qualityCheckStatisticRequest);
    }

    @ApiOperation(httpMethod = "POST",value = "质量检查统计 导出 主体院")
    @PostMapping(value = "/qualityCheck/statistics/export")
    ResponseData<Boolean> exportQualityCheckStatistics(@Validated @RequestBody QualityCheckStatisticRequest qualityCheckStatisticRequest, HttpServletResponse response){
        String signKey = overViewFeignApi.exportQualityCheckStatistics(qualityCheckStatisticRequest).getData();
        FileInfoResponse fileInfoResponse = fileFeignApi.getFileInfo(signKey).getData();
        FileHelper.downloadFile(FDFS_SERVICE_ADDRESS_IN, fileInfoResponse.getStorageGroup(), fileInfoResponse.getPath(), fileInfoResponse.getName(), response);

        return new ResponseData<>().success(true);
    }

    @ApiOperation(httpMethod = "POST",value = "质量检查统计 导出 项目")
    @PostMapping(value = "/qualityCheck/statistics/project/export")
    ResponseData<Boolean> exportQualityCheckStatisticsProject(@Validated @RequestBody QualityCheckStatisticRequest qualityCheckStatisticRequest, HttpServletResponse response){
        String signKey = overViewFeignApi.exportQualityCheckStatisticsProject(qualityCheckStatisticRequest).getData();
        FileInfoResponse fileInfoResponse = fileFeignApi.getFileInfo(signKey).getData();
        FileHelper.downloadFile(FDFS_SERVICE_ADDRESS_IN, fileInfoResponse.getStorageGroup(), fileInfoResponse.getPath(), fileInfoResponse.getName(), response);
        return new ResponseData<>().success(true);
    }

}